/**
 * initialize your data structure here.
 */
 var MedianFinder = function() {
    this.data = [];
};

/** 
 * @param {number} num
 * @return {void}
 */
MedianFinder.prototype.addNum = function(num) {
    this.data.push(num);
    let index= this.data.length -2;
    while(num>this.data[index] && index>=0){
        this.data[index+1] = this.data[index];
        this.data[index] = num;
        index--;
    }
};

/**
 * @return {number}
 */
MedianFinder.prototype.findMedian = function() {
    let length = this.data.length;
    if(length%2){
        return this.data[Math.floor(length/2)];
    }
    return (this.data[length/2]+this.data[length/2-1])/2;
};

/**
 * Your MedianFinder object will be instantiated and called as such:
 * var obj = new MedianFinder()
 * obj.addNum(num)
 * var param_2 = obj.findMedian()
 */